/* eslint-disable no-underscore-dangle */
import 'ant-design-vue/dist/reset.css';
import '@surely-vue/table/dist/index.less';

import { createApp } from 'vue';
import { createPinia } from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
// 平台扩展入口文件
import core from './core';
import router from './router';
import App from './App.vue';
import directives from './directives';

import locale from './locales';

import './app.less';
import './router/router-guards';
import { bindMicroAppEvents, unbindMicroAppEvents } from './utils/micro-app';
let app = null;
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
function mount() {
  app = createApp(App);
  app.use(pinia).use(locale).use(router).use(core).use(directives);
  app.mount('#app');
  window.$app = app;
}
// 作为子应用注册
if (window.__POWERED_BY_WUJIE__) {
  window.__WUJIE_MOUNT = () => {
    mount();
    // 子应用消息接收注册
    bindMicroAppEvents(app, router);
  };
  window.__WUJIE_UNMOUNT = () => {
    unbindMicroAppEvents();
    app.unmount();
  };
  window.__WUJIE.mount();
} else {
  mount();
}
